{% extends "base.html" %}

{% block content %}
<div class="row">
	<div class="span12 offset2">

		<form action="/societies/{{society.slug}}/settings" method="post">
			<fieldset>
				<legend>Edit Society</legend>
				
				<div class="clearfix">
					<label for="{{form.name.name}}">{{form.name.label}}</label>
					<div class="input">
						<input class="xlarge span5 {% if form.name.errors %}error{% endif %}" id="id_{{form.name.name}}" name="{{form.name.name}}" size="30" type="text" value="{{form.name.value}}" />
						<span class="help-inline">{{form.name.errors}}</span>
					</div>
				</div>
				
				<div class="clearfix">
					<label for="{{form.slug.name}}">{{form.slug.label}}</label>
					<div class="input">
						<input class="xlarge span5 {% if form.slug.errors %}error{% endif %}" id="id_{{form.slug.name}}" name="{{form.slug.name}}" size="30" type="text" value="{{form.slug.value}}"/>
						<span class="help-inline">{{form.slug.errors}}</span>
					</div>
				</div>
				
				<div class="clearfix">
					<label for="{{form.email_address.name}}">{{form.email_address.label}}</label>
					<div class="input">
						<input class="xlarge span5 {% if form.email_address.errors %}error{% endif %}" id="id_{{form.email_address.name}}" name="{{form.email_address.name}}" size="30" type="text" value="{{form.email_address.value}}"/>
						<span class="help-inline">{{form.email_address.errors}}</span>
					</div>
				</div>
				
				<div class="clearfix">
					<label for="{{form.description.name}}">{{form.description.label}}</label>
					<div class="input">
						<textarea class="xlarge span8 {% if form.description.errors %}error{% endif %}" id="id_{{form.description.name}}" name="{{form.description.name}}" size="30" type="text">{{form.description.value}}</textarea>
						<span class="help-inline">{{form.description.errors}}</span>
					</div>
				</div>
				
				{% if not society.fb_access_token %}
				<div class="clearfix">
					<label for="facebook_connect_button">Facebook</label>
					<div class="input">
						<a onclick="open_facebook_window()" class="btn facebook_connect_button">Connect to Facebook</a>
					</div>
				</div>
				{% else %}{% if not society.fb_page_id %}
				<div class="clearfix">
		            <label for="page_select">Select Facebook Page</label>
		            <div class="input">
						<select class="span5" name="page_select" id="page_select">
							{% for option in page_options %}
							<option value="{{option.id}}:{{option.access_token}}">{{option.name}}</option>
							{% endfor %}
						</select>
		        	</div>
		        </div>
				{% else %}
				<!--<div class="clearfix">
		            <label for="page_select">Select Facebook Page</label>
		            <div class="input">
						Connected to Facebook
		        	</div>
		        </div>-->
				{% endif %}{% endif %}
				
				<div class="clearfix">
					<div class="input">
						<input type="submit" class="btn primary" value="Save" />
					</div>
				</div>
			</fieldset>
			
			
			<script type="text/javascript">
				function open_facebook_window() {
					window.open("{{facebook_auth_url|safe}}", "Connect to Facebook", "status=0, toolbar=0, height=400, width=600");
				}
			</script>
	</div>
</div>
{% endblock %}